﻿using System.Linq;
using FacialClub.Models.Entities;
using FacialClub.Models.Interfaces;
namespace FacialClub.Models.Repositories
{
    /// <summary>
    /// News/Event Repository
    /// </summary>
    public class NewsEventRepository : INewsEventRepository
    {
        readonly FacialClubEntities _db = new FacialClubEntities();

        /// <summary>
        /// Get News/Event Details by Title
        /// </summary>
        /// <param name="strQuery"></param>
        /// <returns></returns>
        public IQueryable<NewsEvent> FindNewsEventByName(string strQuery)
        {
            return _db.NewsEvents.Where(d => d.Title.Contains(strQuery));
        }

        /// <summary>
        /// Get All News/Event
        /// </summary>
        /// <returns></returns>
        public IQueryable<NewsEvent> FindAllNewsEvent()
        {
            return _db.NewsEvents;
        }

        /// <summary>
        /// Get News/Event by Id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public NewsEvent GetNewsEventById(int id)
        {
            return _db.NewsEvents.SingleOrDefault(d => d.NewsEventId == id);
        }

        /// <summary>
        /// Add News/Event in the Database
        /// </summary>
        /// <param name="newsEvent"></param>
        public void Add(NewsEvent newsEvent)
        {
            _db.NewsEvents.AddObject(newsEvent);
        }

        /// <summary>
        /// Delete News/Event from Database
        /// </summary>
        /// <param name="newsEvent"></param>
        public void Delete(NewsEvent newsEvent)
        {
            _db.NewsEvents.DeleteObject(newsEvent);
        }

        /// <summary>
        /// Save News/Event in the database
        /// </summary>
        public void Save()
        {
            _db.SaveChanges();
        }
    }
}